/**
 * 子弹池
 * by wyy
 */
class bulletPool {
    private static instance: bulletPool;
    private pool: bullet[] = [];
    private bulletOnShow: bullet[] = [];
    constructor(n = 100) {
        this.createBullet(n);
    }
    static getInstance(): bulletPool {
        (!this.instance) && (this.instance = new bulletPool());
        return this.instance;
    }
    createBullet(n) {
        for (let i = 0; i < n; i++) {
            let b = new bullet({});
            this.pool.push(b);
        }
    }
    getBullet() {
        let b: bullet;
        if (this.pool.length <= 0) {
            this.recycleBullet(this.bulletOnShow[0]);
        }
        b = this.pool.pop();
        this.bulletOnShow.push(b);
        return b;
    }
    recycleBullet(b: bullet) {
        this.pool.push(b);
        b.removeFromParent();
        this.bulletOnShow.splice(0, 1);
    }

}